import {SERVER_PROD, SERVER_PRE, SERVER_DEV, SERVER_TEST, SERVER_PINMING_TEST, SERVER_PINMING_K8_TEST} from './server'
import Select from './components/select/index.js'
import Checked from './components/checked/index.js'
import Radio from './components/radio/radio.vue'
import Dialog from './components/dialog/Dialog.vue'
import Nav from './components/nav/nav.vue'
import Search from './components/search/index.js'
import VueJsonp from 'vue-jsonp'
import axios from 'axios' // ajax
import qs from 'qs'
import local from 'store'
import Upload from './components/upload/index.js'
import Retrieve from './components/retrieve/index.js'
import Paginate from './components/paginate/index.js'

import Row from './components/layout/row/index.js'
import Col from './components/layout/col/index.js'
import Table from './components/table/index.js'
import SearchAd from './components/SearchAd/index.js'
import Date from './components/datepicker/index.js'
import GoldLoading from './components/loading/goldLoading.vue'
import User from './components/appUser/user.vue'
import FilePreview from './components/appPreview/Preview.vue'
import AreaPicker from './components/areaPicker/areaPicker.vue'
import AppBack from './components/back/AppBack.vue'
import FileList from './components/fileList/fileList.vue'
import UploadList from './components/upload/src/FileList.vue'
import UploadImg from './components/upload/src/FileImg.vue'
import Tree from './components/tree/index.js'
import TreeGrid from './components/treeGrid/index.js'
import AutoComplete from './components/autoComplete/index.js'
import Talk from './components/appTalk/index.js'
import Content from './components/appContent/index.js'
import None from './components/none/none.vue'
import Depart from './components/retrieve/src/depart.vue'
import Worker from './components/retrieve/src/worker.vue'
import UnderDesign from './components/underDesign/underDesign.vue'
import Switches from './components/switch/switches.vue'
import Tab from './components/tab/tab.vue'
import Link from './components/link/link.vue'
import Ueditor from './components/ueditor/ueditor.vue'
import Project from './components/retrieve/src/constructProject/project.vue'
import projectRetrieve from './components/retrieve/src/projectRetrieve.vue'
import Host from './components/host/Host.vue'
import editProject from './components/real/editProject'
import stageList from './components/stageList/stageList.vue'
import cooperator from './components/real/cooperator/cooperator.vue'
import qriously from './components/qrcode/qriously.vue'
// import weather from './components/weather/weather.vue'

import vuex from './store/index.js'

import Message from './components/message/index.js' // 警告
import MessageBox from './components/MessageBox/index.js' // 警告(带确定取消按钮)

// 验证
import validationInstall from './components/vaildation/install'
import validation from './components/vaildation/directive'

// 滚动条
import Vuebar from 'vuebar'

import echarts from 'echarts'

import {getCookie, setCookie, delCookie} from './tool/cookie.js'
import {getQueryStringKey, getQueryStringValue} from './tool/getQueryString.js'

// 导入全局函数
import Download from './tool/download.js' // 下载
import Browser from './tool/broeser/browser.js' // 判断浏览器类型
import windowOpen from './tool/windowOpen.js' // 新开窗口
import exportData from './tool/export.js' // 导出数据
import IconColor from './components/appPreview/iconColor.js' // 图标背景色
import SparkMd5 from 'spark-md5'
import throttle from './tool/throttle.js' // 函数节流

import Moment from 'moment'
import 'moment/locale/zh-cn'
Moment.locale('zh-cn')

// import velocity from 'velocity-animate'

import accounting from './filter/accounting.js'

import draggable from 'vuedraggable'

// 本地数据库
import DesignDB from './components/indexedDB/designDB.js'

// 注册全局过滤器
import formatSize from './filter/formatSize.js'
import date from './filter/date.js'
import sex from './filter/sex.js'

// 注册全局指令
import drag from './directives/drag.js'

import focus from './directives/focus.js'
// 查看视频
import video from './components/video/index'

// 查看图片
import imagePreview from './components/preview/index'

// 批量导入
import importData from './components/import/index'

// 导出弹窗
import exportDialog from './components/exportDialog/index'

// 引入BMap
import BaiduMap from 'vue-baidu-map'

import EmojiConvertor from 'emoji-Js'

// 全局上传组件
import uploadG from './components/upload/global/index'

import getCurrentUser from './tool/getCurrentUser.js'

// 存储请求url
import requestMap from './tool/requestMap.js'

import previewFile from './components/appPreview/file.js'

import OSS from 'ali-oss'

import './tool/requestAnimationFrame'

import { VTooltip, VPopover } from 'v-tooltip'

import Weibo from './components/weibo/weibo.vue'

export {
  install,
  vuex
}

export default {
  install (Vue) {
    install(Vue)
  },
  vuex
}

function install (Vue) {
  Vue.component(Select.name, Select)
  Vue.component(Checked.name, Checked)
  Vue.component(Radio.name, Radio)
  Vue.component(Dialog.name, Dialog)
  Vue.component(Search.name, Search)
  Vue.component(Paginate.name, Paginate)
  Vue.component(Nav.name, Nav)
  Vue.component(Upload.name, Upload)
  Vue.component(Retrieve.name, Retrieve)
  Vue.component(Weibo.name, Weibo)
  Vue.component(Row.name, Row)
  Vue.component(Col.name, Col)
  Vue.component(Table.name, Table)
  Vue.component(SearchAd.name, SearchAd)
  Vue.component(Date.name, Date)
  Vue.component(GoldLoading.name, GoldLoading)
  Vue.component(User.name, User)
  Vue.component(FilePreview.name, FilePreview)
  Vue.component(AreaPicker.name, AreaPicker)
  Vue.component(AppBack.name, AppBack)
  Vue.component(FileList.name, FileList)
  Vue.component(UploadList.name, UploadList)
  Vue.component(UploadImg.name, UploadImg)
  Vue.component(Tree.name, Tree)
  Vue.component(TreeGrid.name, TreeGrid)
  Vue.component(AutoComplete.name, AutoComplete)
  Vue.component(Talk.name, Talk)
  Vue.component(Content.name, Content)
  Vue.component(None.name, None)
  Vue.component(Depart.name, Depart)
  Vue.component(Worker.name, Worker)
  Vue.component(Project.name, Project)
  Vue.component(UnderDesign.name, UnderDesign)
  Vue.component(Switches.name, Switches)
  Vue.component(Tab.name, Tab)
  Vue.component(Link.name, Link)
  Vue.component(Ueditor.name, Ueditor)
  Vue.component(Host.name, Host)
  Vue.component(editProject.name, editProject)
  Vue.component(stageList.name, stageList)
  Vue.component(cooperator.name, cooperator)
  Vue.component(projectRetrieve.name, projectRetrieve)
  Vue.component(qriously.name, qriously)
  // Vue.component(weather.name, weather)
  Vue.component('draggable', draggable)

  Vue.filter('formatSize', formatSize)
  Vue.filter('accounting', accounting)
  Vue.filter('date', date)
  Vue.filter('sex', sex)

  Vue.directive('tooltip', VTooltip)
  Vue.component('v-popover', VPopover)

  Vue.use(validationInstall)
  Vue.use(VueJsonp)
  Vue.use(Vuebar)
  Vue.use(video)
  Vue.use(imagePreview)
  Vue.use(importData)
  Vue.use(exportDialog)
  Vue.use(uploadG)
  Vue.use(requestMap)
  Vue.use(BaiduMap, {
    ak: 'MErGAwKAYaNnw8jTxTX0hYyscdcdH8Rl'
  })

  Vue.directive('focus', focus)
  Vue.directive('drag', drag)
  Vue.directive('validation', validation)

  Vue.prototype.$axios = axios
  axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
  axios.defaults.withCredentials = true
  Vue.prototype.$qs = qs
  Vue.prototype.$getCookie = getCookie
  Vue.prototype.$setCookie = setCookie
  Vue.prototype.$delCookie = delCookie
  Vue.prototype.$Download = Download
  Vue.prototype.$GetCurrentUser = getCurrentUser
  Vue.prototype.$Browser = Browser
  Vue.prototype.$windowOpen = windowOpen
  Vue.prototype.$export = exportData
  Vue.prototype.$Throttle = throttle
  Vue.prototype.$local = local
  Vue.prototype.$DesignDB = DesignDB
  Vue.prototype.$accounting = accounting
  Vue.prototype.$SparkMd5 = SparkMd5
  Vue.prototype.$IconColor = IconColor
  Vue.prototype.$previewFile = previewFile
  Vue.prototype.$Echarts = echarts
  Vue.prototype.$moment = Moment
  // Vue.prototype.$velocity = velocity
  Vue.prototype.$message = Message
  Vue.prototype.$MessageBox = MessageBox
  Vue.prototype.$getQueryStringKey = getQueryStringKey
  Vue.prototype.$getQueryStringValue = getQueryStringValue
  Vue.prototype.$OSS = OSS
  Vue.prototype.SERVER_PROD = SERVER_PROD
  Vue.prototype.SERVER_PRE = SERVER_PRE
  Vue.prototype.SERVER_DEV = SERVER_DEV
  Vue.prototype.SERVER_TEST = SERVER_TEST
  Vue.prototype.SERVER_PINMING_TEST = SERVER_PINMING_TEST
  Vue.prototype.SERVER_PINMING_K8_TEST = SERVER_PINMING_K8_TEST
  if (process.env.NODE_TYPE === 'prod') {
    Vue.prototype.$site = SERVER_PROD
  } else {
    if (Vue.prototype.$getCookie('server')) {
      Vue.prototype.$site = JSON.parse(Vue.prototype.$getCookie('server'))
    } else {
      Vue.prototype.$site = SERVER_PROD
    }
  }
  Vue.prototype.$emoji = new EmojiConvertor()
  Vue.prototype.$emoji.img_sets.apple.path = `${Vue.prototype.$site.libServer}/front/face/`
}
